//
//  SinaNavController.swift
//  Sina
//
//  Created by 星仔 on 2017/2/23.
//  Copyright © 2017年 xingZai. All rights reserved.
//

import UIKit

class SinaNavController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        self.navigationBar.isHidden = true
        
    }

    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if childViewControllers.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
            //从导航中取出要跳转过去的控制器设置控制器左边导航返回，如果是第一层显示上一页标题，否则显示返回
            if  let vc = viewController as? SinaBaseController{
                
                var title = "返回"
                if childViewControllers.count == 1 {//第一层
                    title = childViewControllers.first?.title ?? "返回"
                }
                vc.navBarItems.leftBarButtonItem = UIBarButtonItem(title: title, target: self
                    , action: #selector(popBack), isBack: true)
                
            }
            
        }
        super.pushViewController(viewController, animated: true)
    }
    @objc private func popBack(){
        popViewController(animated: true)
    }

}
